package com.pjchat.pjchatclient.printer;

import javax.swing.JTextArea;

import com.ita.im.model.Message;

public class ClientFramePrinter {
	private static ClientFramePrinter instance;

	private ClientFramePrinter() {

	}

	public static ClientFramePrinter getinstance() {
		if (instance == null) {
			instance = new ClientFramePrinter();
		}
		return instance;
	}

	public void printMessage(JTextArea jtp, Message message) {
		String result = "";
		result += message.getFrom().getName();
		result += "(" + message.getTime() + ")";
		if (message.isShake()) {
			result += "is SHAKING ";
			result += message.isToAll() ? "ALL" : message.getTo().getName()
					+ ".";
		} else {
			result += " to ";
			result += message.isToAll() ? "ALL" : message.getTo().getName();
			result += ":" + message.getContent();
		}
		jtp.setText(jtp.getText() + "\n\n" + result);
		System.out.println(result);
	}
}
